tTrawler._services.sohunt = {
  profile  : {
    name : "IsoHunt",
    desc : "World's largest BitTorrent and P2P search engine",
    site : "http://isohunt.com"
  }, 
  
  category : {
    video : ["Video/Movies", "TV", "Music Video"],
    audio : ["Audio"],
    image : ["Pictures"],
    exec  : ["Games", "Applications"]
  },
  
  method   : "GET",
  query    : "ihq={SearchTerm}",
  url      : "http://somedomainthatdoesntexist.com/torrents/?",
  
  getItems : function (slot) {  
 
    var response = tTrawler.http.requestSlots[slot].responseText; // get this slots response
    var count = this.getPageCount(response); // How many pages of results do we need to sift through?
    if (count > 0) {
      var maxPages = tTrawler.config.resultsMaxPageCount;
      count = (count > maxPages)? maxPages : count;   
   
      for (i=1;i<=count;i++) {
        tTrawler.http.httpRequest(
          this.url, this.method,
          this.query.replace("{SearchTerm}", tTrawler.search.searchTerm) + "&ihs1=12&iho1=d&iht=-1&ihp=" + i,
          "tTrawler._services.isohunt.getPage(slot)");
      };  
    };
   
  },
  
  getPageCount : function (r) {
    if (r.indexOf('<u>Page 1 of') > 0) {
      var buff = r.split('<u>Page 1 of');
      r = buff[1].split('</u>')[0];
    } else {r=0;}
    return r;
  },
  
  getPage : function (slot) {
   
    //Begin Hack... 
    
    var response = tTrawler.http.requestSlots[slot].responseText;
    var chunk = [];
    
    chunk[0] = response.split("<tr class=\"hlRow\" onClick="); // Split the string by each row
    
    for(i=1;i<=(chunk[0].length-1);i++) { // loop through the rows
      var results = [];
      
      // make sure to ignore isohunt releases (because of their irregular formating)
      if (chunk[0][i].split("\"")[1] != "window.location=RL" + i +".href;") { 
        
        results.push("http://isohunt.com/download/" + chunk[0][i].split("/")[2] + "/"); //get torrents url
        chunk[1] = chunk[0][i].split("<td class=\"row3\"") //split the td's
     
        for(ii=1;ii<=6;ii++) { // loop through each td (TYPE, AGE, NAME, SIZE, SEEDS, LEECHES) 
                   
          val = chunk[1][ii].split("</td>")[0];
        
          //This switch is some gross string sanitizing *MUST CLEAN*
          switch (ii) {
            case 1:
              val = val.substr(1);
              switch(val) {
                case "Video/Movies" :
                case "TV" :
                case "Music Video" :
                  val = "video-icon";
                  break;
                case "Audio" :
                  val = "audio-icon";
                  break;
                case "Pics":
                  val ="image-icon";
                  break;
                case "Games":
                case "Apps":
                  val = "exec-icon";
                  break;  
                default :
                  val="default-icon";
                  break; 
              };
            break;
            case 2:case 5:case 6:
              val = val.substr(1);
              break;
            case 3:
              val = tTrawler.helper.replaceAll(["id=name","<b>","</b>"], ["","",""], val);
 
              val = val.substr(val.indexOf(">")+1);
              if (val.indexOf("<br>") >= 0) {
                val = val.split("<br>")[1];
              }
              if (val.indexOf("<span") >= 0) {
                val = val.split("<span title=\"")[1];
                val = val.split("\">")[0];
              }
              break;
            case 4:
              val = val.split(">")[1];
              break;
          };
          
          results.push(val);  // Push the value into this result
        }; 
        tTrawler.search.appendResult(results);
       
      } 
    }
  }
  /*--*/
}